layui.define(['element', 'utils', 'conf', 'NProgress'], function (exports) {
    var utils = layui.utils,
        element = layui.element,
        config = layui.conf,
        NProgress = layui.NProgress;


    /**
     * @author: ares
     * @date: 2020/12/23 11:08
     * @description: 切换页面
     * @param{object} data
     */
    function changePage(data) {
	    utils.loadView(data.filePath, function () {
            utils.highLightAside();
            utils.updateBreadcrumb(router);
            element.render();
        });
    }

    var routes = {
            '/homepage': function () {
                router.meta = {
                    breadcrumb: [
                        {
                            path: config.homePagePath,
                            title: config.homePageTitle,
                            filePath: config.homePageFilePath,
                            icon: config.homePageIcon,
                        }
                    ]
                };
                router.params = {};
            },
            '/setting': {
                '/user': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/setting',
                                title: '系统管理',
                            },
                            {
                                path: '/setting/user',
                                title: '用户管理',
                                filePath: 'pages/user/list.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
            },
            '/user': {
                '/info': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '',
                                title: '用户管理',
                                filePath: '',
                                icon: ''
                            },
                            {
                                path: '/user/info',
                                title: '个人资料',
                                filePath: 'pages/user/userinfo.html',
                                icon: ''
                            }
                        ]
                    };
                    router.params = {};
                },
                '/modifyPwd': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '',
                                title: '用户管理',
                                filePath: '',
                                icon: ''
                            },
                            {
                                path: '/user/modifyPwd',
                                title: '修改密码',
                                filePath: 'pages/user/changePwd.html',
                                icon: ''
                            }
                        ]
                    };
                    router.params = {};
                },
            },
        },
        router = Router(routes).configure({
            on: function () {
                router.meta && changePage(router.meta.breadcrumb.slice(-1)[0]);
            },
            before: function () {
                NProgress.done();
            },
            after: function () {
                NProgress.start();
                NProgress.inc();
            },
            notfound: function () {
                console.log('>>>路由匹配失败<<<')
            }
        });
    router.init();
    exports('routers', router)
})